package org.jarraiders.musiclibrary.domain;

import java.io.Serializable;
import java.util.UUID;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Type;

/**
 * @author AlteroStudio
 */
@Entity
@Table(name = "tracks", schema = "public")
public class Track implements Serializable {

	private static final long serialVersionUID = -1541415722096799415L;

	@Id
	@Column(name = "tr_id", columnDefinition = "uuid")
	@Type(type = "pg-uuid")
	@Basic(optional = false)
	private UUID trackId;

	@Column(name = "tr_name")
	@Basic(optional = false)
	private String trackTitle;

	@Column(name = "tr_number")
	private int trackNumber;

	@Fetch(FetchMode.JOIN)
	@ManyToOne(optional = false, fetch = FetchType.EAGER)
	@JoinColumn(name = "album_id", referencedColumnName = "al_id")
	private Album album_id;
	
	public Track(){
		
	}

	public Track(UUID uuid, String trackTitle, int trackNumber, Album album){
		this.album_id=album;
		this.trackId=uuid;
		this.trackTitle=trackTitle;
		this.trackNumber=trackNumber;
	}
	public UUID getTrackId() {
		return trackId;
	}

	public void setTrackId(UUID trackId) {
		this.trackId = trackId;
	}

	public String getTrackTitle() {
		return trackTitle;
	}

	public void setTrackTitle(String trackTitle) {
		this.trackTitle = trackTitle;
	}

	public int getTrackNumber() {
		return trackNumber;
	}

	public void setTrackNumber(int trackNumber) {
		this.trackNumber = trackNumber;
	}

	public Album getReferencedAlbum() {
		return album_id;
	}

	public void setReferencedAlbum(Album refferencedAlbum) {
		this.album_id = refferencedAlbum;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Track [trackId=");
		builder.append(trackId);
		builder.append(", trackTitle=");
		builder.append(trackTitle);
		builder.append(", trackNumber=");
		builder.append(trackNumber);
		builder.append(", refferencedAlbum=");
		builder.append(album_id);
		builder.append("]");
		return builder.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((trackId == null) ? 0 : trackId.hashCode());
		result = prime * result + trackNumber;
		result = prime * result
				+ ((trackTitle == null) ? 0 : trackTitle.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Track other = (Track) obj;
		if (trackId == null) {
			if (other.trackId != null)
				return false;
		} else if (!trackId.equals(other.trackId))
			return false;
		if (trackNumber != other.trackNumber)
			return false;
		if (trackTitle == null) {
			if (other.trackTitle != null)
				return false;
		} else if (!trackTitle.equals(other.trackTitle))
			return false;
		return true;
	}
}
